import sqlite3
import os

# 获取当前脚本所在目录
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建数据库路径，向上两级目录
db_path = os.path.join(current_dir, '../../trade_monitor.db')

try:
    # 连接到数据库
    conn = sqlite3.connect(db_path)
    cursor = conn.cursor()

    # 查询限额止损的值
    cursor.execute("SELECT name, limit_stoploss FROM products WHERE is_monitored = 1")
    results = cursor.fetchall()

    if results:
        print("以下是数据库中限额止损的值：")
        for row in results:
            product_name, stop_loss_limit = row
            print(f"品种: {product_name}, 限额止损值: {stop_loss_limit}")
    else:
        print("未找到被监控品种的限额止损值。")

    # 关闭数据库连接
    conn.close()
except Exception as e:
    print(f"从数据库获取限额止损值时出错: {e}")
